Skip to content

Absolute X Relative links - #60

Merged
tg666 merged 1 commit into
masterfrom
feature/relative-links
Feb 20, 2026
Merged

Absolute X Relative links#60
tg666 merged 1 commit into
masterfrom
feature/relative-links

Conversation

@tg666

@tg666 tg666 commented Feb 20, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features

    • Added optional parameter to control absolute vs. relative URL generation for links and image source sets. Defaults to absolute URLs for backward compatibility.
  • Chores

    • Updated file storage dependency to v1.4.0.

- added argument `$absolute = true` to `LinkGeneratorInterface` and `FileInfoInterface`
- added unit tests
@coderabbitai

coderabbitai Bot commented Feb 20, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The PR extends the image storage library's link generation system to support both absolute and relative URL generation. An $absolute boolean parameter (defaulting to true) is added throughout the method call chain, from public APIs down to the source set generator, with updated tests validating both behaviors. The file-storage dependency is also bumped to ^1.4.0.

Changes

Cohort / File(s) Summary
Dependency Update
composer.json
Version bump for 68publishers/file-storage from ^1.3.0 to ^1.4.0.
Public API Interfaces
src/FileInfoInterface.php, src/LinkGenerator/LinkGeneratorInterface.php
Added optional bool $absolute = true parameter to srcSet() and link() method signatures.
Core Implementation
src/FileInfo.php, src/ImageStorage.php, src/LinkGenerator/LinkGenerator.php
Implemented bool $absolute = true parameter in method signatures and forwarded it via named arguments to downstream generators and link builders.
Generator & Facade
src/Responsive/SrcSetGenerator.php, src/Responsive/Descriptor/ArgsFacade.php
Updated SrcSetGenerator::generate() to accept bool $absolute and encode it in cache keys (abs/rel prefix); ArgsFacade constructor now accepts bool $absolute and applies it to link generation calls.
Test Coverage
tests/FileInfoTest.phpt, tests/ImageStorageTest.phpt, tests/LinkGenerator/LinkGeneratorTest.phpt, tests/Responsive/Descriptor/ArgsFacadeTest.phpt, tests/Responsive/SrcSetGeneratorTest.phpt
Added test methods validating relative SrcSet/link generation when $absolute = false; updated existing mock expectations to include the new parameter; enhanced cache key assertions and ArgsFacade property validation.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant FileInfo
    participant LinkGenerator
    participant SrcSetGenerator
    participant ArgsFacade

    Client->>FileInfo: srcSet(descriptor, absolute: true)
    FileInfo->>LinkGenerator: srcSet(info, descriptor, absolute: true)
    LinkGenerator->>SrcSetGenerator: generate(descriptor, pathInfo, absolute: true)
    SrcSetGenerator->>ArgsFacade: createLink(absolute: true)
    ArgsFacade->>LinkGenerator: link(pathInfo, absolute: true)
    LinkGenerator-->>ArgsFacade: absolute URL
    ArgsFacade-->>SrcSetGenerator: cache key (abs::...)
    SrcSetGenerator-->>LinkGenerator: SrcSet
    LinkGenerator-->>FileInfo: SrcSet
    FileInfo-->>Client: SrcSet (absolute paths)

    Client->>FileInfo: srcSet(descriptor, absolute: false)
    FileInfo->>LinkGenerator: srcSet(info, descriptor, absolute: false)
    LinkGenerator->>SrcSetGenerator: generate(descriptor, pathInfo, absolute: false)
    SrcSetGenerator->>ArgsFacade: createLink(absolute: false)
    ArgsFacade->>LinkGenerator: link(pathInfo, absolute: false)
    LinkGenerator-->>ArgsFacade: relative URL
    ArgsFacade-->>SrcSetGenerator: cache key (rel::...)
    SrcSetGenerator-->>LinkGenerator: SrcSet
    LinkGenerator-->>FileInfo: SrcSet
    FileInfo-->>Client: SrcSet (relative paths)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

enhancement

Poem

A rabbit hops through links so bright,
Absolute paths or relative light!
Each parameter flows down the chain,
With $absolute dancing in the refrain—
Caching absurdly relative gains! 🐰✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 5.56% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Absolute X Relative links' directly describes the main feature added: support for choosing between absolute and relative links throughout the codebase.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/relative-links

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
tests/Responsive/SrcSetGeneratorTest.phpt (1)

200-226: assertFacadePropertiesRelative duplicates assertFacadeProperties almost entirely.

The two helpers differ only in Assert::true vs Assert::false on $facade->absolute. Consider collapsing them into a single parameterized helper:

♻️ Suggested refactor
-    private function assertFacadeProperties(ArgsFacade $facade, LinkGeneratorInterface $linkGenerator, ModifierFacadeInterface $modifierFacade, PathInfoInterface $pathInfo): void
-    {
-        call_user_func(Closure::bind(
-            static function () use ($facade, $linkGenerator, $modifierFacade, $pathInfo): void {
-                Assert::same($facade->linkGenerator, $linkGenerator);
-                Assert::same($facade->modifierFacade, $modifierFacade);
-                Assert::same($facade->pathInfo, $pathInfo);
-                Assert::true($facade->absolute);
-            },
-            null,
-            ArgsFacade::class,
-        ));
-    }
-
-    private function assertFacadePropertiesRelative(ArgsFacade $facade, LinkGeneratorInterface $linkGenerator, ModifierFacadeInterface $modifierFacade, PathInfoInterface $pathInfo): void
-    {
-        call_user_func(Closure::bind(
-            static function () use ($facade, $linkGenerator, $modifierFacade, $pathInfo): void {
-                Assert::same($facade->linkGenerator, $linkGenerator);
-                Assert::same($facade->modifierFacade, $modifierFacade);
-                Assert::same($facade->pathInfo, $pathInfo);
-                Assert::false($facade->absolute);
-            },
-            null,
-            ArgsFacade::class,
-        ));
-    }
+    private function assertFacadeProperties(
+        ArgsFacade $facade,
+        LinkGeneratorInterface $linkGenerator,
+        ModifierFacadeInterface $modifierFacade,
+        PathInfoInterface $pathInfo,
+        bool $absolute = true,
+    ): void {
+        call_user_func(Closure::bind(
+            static function () use ($facade, $linkGenerator, $modifierFacade, $pathInfo, $absolute): void {
+                Assert::same($facade->linkGenerator, $linkGenerator);
+                Assert::same($facade->modifierFacade, $modifierFacade);
+                Assert::same($facade->pathInfo, $pathInfo);
+                Assert::same($absolute, $facade->absolute);
+            },
+            null,
+            ArgsFacade::class,
+        ));
+    }

Then update the call sites:

-                $this->assertFacadePropertiesRelative($facade, $linkGenerator, $modifierFacade, $pathInfo);
+                $this->assertFacadeProperties($facade, $linkGenerator, $modifierFacade, $pathInfo, false);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/Responsive/SrcSetGeneratorTest.phpt` around lines 200 - 226, The two
duplicate test helpers assertFacadeProperties and assertFacadePropertiesRelative
should be collapsed into a single parameterized helper (e.g.,
assertFacadeProperties(ArgsFacade $facade, LinkGeneratorInterface
$linkGenerator, ModifierFacadeInterface $modifierFacade, PathInfoInterface
$pathInfo, bool $expectedAbsolute)) that performs the three Assert::same checks
on $facade->linkGenerator, $facade->modifierFacade and $facade->pathInfo and
then asserts $facade->absolute equals $expectedAbsolute (use Assert::true when
$expectedAbsolute is true, Assert::false when false, or a single
equality/assertSame on the boolean). Replace all callers of
assertFacadePropertiesRelative to call the new helper with expectedAbsolute =
false and existing callers of assertFacadeProperties with expectedAbsolute =
true, then remove the now-unused duplicate method.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/Responsive/SrcSetGeneratorTest.phpt`:
- Around line 200-226: The two duplicate test helpers assertFacadeProperties and
assertFacadePropertiesRelative should be collapsed into a single parameterized
helper (e.g., assertFacadeProperties(ArgsFacade $facade, LinkGeneratorInterface
$linkGenerator, ModifierFacadeInterface $modifierFacade, PathInfoInterface
$pathInfo, bool $expectedAbsolute)) that performs the three Assert::same checks
on $facade->linkGenerator, $facade->modifierFacade and $facade->pathInfo and
then asserts $facade->absolute equals $expectedAbsolute (use Assert::true when
$expectedAbsolute is true, Assert::false when false, or a single
equality/assertSame on the boolean). Replace all callers of
assertFacadePropertiesRelative to call the new helper with expectedAbsolute =
false and existing callers of assertFacadeProperties with expectedAbsolute =
true, then remove the now-unused duplicate method.

@tg666
tg666 merged commit 57d73ed into master Feb 20, 2026
9 checks passed
@tg666
tg666 deleted the feature/relative-links branch February 20, 2026 03:33
@coderabbitai coderabbitai Bot mentioned this pull request Feb 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant